<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>问题药品信息</title>
  <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/static/admin/style.css}" media="all">
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px">
        <form class="layui-form layui-form-pane" action="">
          <input name="id" th:value="${obj?.id}" class="layui-input layui-hide">
          <div class="layui-form-item">
            <label class="layui-form-label">药品名称</label>
            <div class="layui-input-block">
              <select name="dname" id="dname"></select>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-block">
              <input type="text" name="count" th:value="${obj?.count}" lay-verify="required" placeholder="请输入数量" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-block">
              <input type="text" name="price" th:value="${obj?.price}" lay-verify="required" placeholder="请输入单价" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">原因</label>
            <div class="layui-input-block">
              <textarea  name="reason" th:text="${obj?.reason}" lay-verify="required" placeholder="请输入原因" autocomplete="off" class="layui-textarea"></textarea>
            </div>
          </div>
          <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-front-submit" id="LAY-front-submit" value="确认">
          </div>
        </form>
      </div>
    </div>
  </div>
  <script th:src="@{/static/layui/layui.js}"></script>
  <script>
    layui.use(['form','laydate','jquery'],function () {
      var form = layui.form;
      var laydate = layui.laydate;
      var $ = layui.jquery;


      //当前药品的值
      var currentDname = '[[${obj?.dname}]]';
      console.log(currentDname);

      //获取供应商列表
      $.ajax({
        url:'/drugInfo/drugInfoList',
        dataType:'json',
        type:'post',
        cache:false,
        success:function (data) {
          console.log(data);
          $('#dname').prepend('<option value="">请选择</option>');
          for (let i = 0; i < data.length; i++) {
            console.log(data);
            if (data.data[i].name==currentDname){
              $('#supplier').append("<option selected value='"+data.data[i].dname+"'>data.data[i].dname</option>");
            }else {
              $('#supplier').append("<option value='"+data.data[i].dname+"'>data.data[i].dname</option>");
            }
          }
          form.render();    //下拉列表渲染，把内容加进去
        }
      });

    });

  </script>
</body>
</html>